// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.network.packets.hit;

import java.nio.ByteBuffer;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoZombie;
import zombie.core.network.ByteBufferWriter;
import zombie.core.raknet.UdpConnection;
import zombie.network.PacketValidator;
import zombie.network.packets.INetworkPacket;

public class ZombieHitPlayerPacket extends HitCharacterPacket implements INetworkPacket {
    protected final Zombie wielder = new Zombie();
    protected final Player target = new Player();
    protected final Bite bite = new Bite();

    public ZombieHitPlayerPacket() {
        super(HitCharacterPacket.HitType.ZombieHitPlayer);
    }

    public void set(IsoZombie _wielder, IsoPlayer _target) {
        this.wielder.set(_wielder, false);
        this.target.set(_target, false);
        this.bite.set(_wielder);
    }

    @Override
    public void parse(ByteBuffer b, UdpConnection connection) {
        this.wielder.parse(b, connection);
        this.target.parse(b, connection);
        this.target.parsePlayer(connection);
        this.bite.parse(b, connection);
    }

    @Override
    public void write(ByteBufferWriter b) {
        super.write(b);
        this.wielder.write(b);
        this.target.write(b);
        this.bite.write(b);
    }

    @Override
    public boolean isRelevant(UdpConnection connection) {
        return this.target.isRelevant(connection);
    }

    @Override
    public boolean isConsistent() {
        return super.isConsistent() && this.target.isConsistent() && this.wielder.isConsistent();
    }

    @Override
    public String getDescription() {
        return super.getDescription()
            + "\n\tWielder "
            + this.wielder.getDescription()
            + "\n\tTarget "
            + this.target.getDescription()
            + "\n\tBite "
            + this.bite.getDescription();
    }

    @Override
    protected void preProcess() {
        this.wielder.process();
        this.target.process();
    }

    @Override
    protected void process() {
        this.bite.process((IsoZombie)this.wielder.getCharacter(), this.target.getCharacter());
    }

    @Override
    protected void postProcess() {
        this.wielder.process();
        this.target.process();
    }

    @Override
    protected void attack() {
    }

    @Override
    protected void react() {
        this.wielder.react();
        this.target.react();
    }

    @Override
    public boolean validate(UdpConnection connection) {
        if (!PacketValidator.checkShortDistance(connection, this.wielder, this.target, ZombieHitPlayerPacket.class.getSimpleName())) {
            return false;
        } else {
            return !PacketValidator.checkOwner(connection, this.wielder, ZombieHitPlayerPacket.class.getSimpleName())
                ? false
                : PacketValidator.checkTarget(connection, this.target, ZombieHitPlayerPacket.class.getSimpleName());
        }
    }
}
